#! /usr/bin/python
# -*- coding: cp1250 -*-
#sys.path.append(r'C:\AFT\.pylib')

import glob, sys, os, re, string
import pepe.txt.bigtxt as bt

zf4     = lambda x_s:   string.zfill(x_s, 4)

def __do(inpfile, cdelimiter):
    out_h = {}
    #for infile_s in glob.glob(infile_s):
    linecnt_n = 0
    for line_s in bt.lines(inpfile):
        cols_l = string.split(line_s[:-1], cdelimiter)
        linecnt_n += 1
        if linecnt_n == 1:
            for hc_index, hc_value in enumerate(cols_l):
                out_h[zf4(hc_index)] = [hc_value,0,'']
        else:
            for dc_index, dc_value in enumerate(cols_l):
                if len(dc_value) > out_h[zf4(dc_index)][1]:
                    out_h[zf4(dc_index)][1] = len(dc_value)
                    out_h[zf4(dc_index)][2] = line_s
    for k in sorted(out_h.keys()):
        print k, out_h[k]

HELP = """Purpose: Prints spans of csv file individual columns.
Syntax: csv-cspan <inpfile> <cdelimiter>
Example: csv-cspan test.csv \"|\""""

if __name__ == "__main__":
    #print __do("test.csv", "|", 1)
    #__do('data.dat', '^')
    if len(sys.argv) <> 3:
        print HELP
    else:
        __do(sys.argv[1], sys.argv[2])


